//
//  LGMedicineBallDetailHeader.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/25.
//  药球患者详情页-Header

#import "LGMedicineBallDetailHeader.h"

@interface LGMedicineBallDetailHeader()
/**   */
@property (nonatomic , strong)CAGradientLayer *shadowLayer;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UIImageView *vipView;
/**   */
@property (nonatomic , strong)UIButton *doctorBtn;
/**   */
@property (nonatomic , strong)UILabel *numberLabel;
/**   */
@property (nonatomic , strong)UILabel *phoneLabel;
/**   */
@property (nonatomic , strong)UILabel *recordTitle;

@end

@implementation LGMedicineBallDetailHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.shadowLayer.frame = frame;
        [self createSubView];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.nameLabel.text = LGNSString(dataDic[@"realname"]);
    [self.vipView sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"vipicon"])]];
    NSString *doctorName = LGNSString(dataDic[@"doctor_name"]);
    CGFloat left = (LGNSString(dataDic[@"vipicon"]).length > 0)?viewPix(24):viewPix(4);
    CGFloat width = [doctorName textWidthWithFont:LGFontWeight(12, UIFontWeightMedium) maxHeight:MAXFLOAT];
    width = (doctorName.length>0)?width+viewPix(35):0;
    [self.doctorBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(left);
        make.width.equalTo(@(width));
    }];
    self.doctorBtn.hidden = (doctorName.length>0)?NO:YES;
    [self.doctorBtn setTitle:doctorName forState:UIControlStateNormal];
    
    //性别、年龄、病案号
    NSString *gender = LGNSString(dataDic[@"gender"]);
    NSString *age = LGNSString(dataDic[@"age"]);
    NSString *number = LGNSString(dataDic[@"hospital_bano"]);
    if(gender.length>0 && age.length >0){
        self.numberLabel.text = [NSString stringWithFormat:@"%@ | %@岁 %@",gender,age,number];
    }else if (gender.length > 0 && age.length == 0){
        self.numberLabel.text = [NSString stringWithFormat:@"%@ %@",gender,number];
    }else if (gender.length == 0 && age.length>0){
        self.numberLabel.text = [NSString stringWithFormat:@"%@岁 %@",age,number];
    }else{
        self.numberLabel.text = [NSString stringWithFormat:@"%@",number];
    }
    
    NSString *mobile = LGNSString(dataDic[@"mobile"]);
    self.phoneLabel.text = mobile;
    self.phoneLabel.hidden = (mobile.length == 0)?YES:NO;
    self.phoneButton.hidden = (mobile.length == 0)?YES:NO;
}
 
-(void)layoutSubviews{
    [super layoutSubviews];
    self.shadowLayer.frame = CGRectMake(0,0,Screen_W,self.bounds.size.height);
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.layer addSublayer:self.shadowLayer];
    [self addSubview:self.nameLabel];
    [self addSubview:self.vipView];
    [self addSubview:self.doctorBtn];
    [self addSubview:self.numberLabel];
    [self addSubview:self.phoneLabel];
    [self addSubview:self.phoneButton];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(viewPix(12));
        make.left.equalTo(self).offset(viewPix(16));
    }];
    [self.vipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(3));
        make.width.height.equalTo(@(viewPix(16)));
        make.centerY.equalTo(self.nameLabel);
    }];
    [self.doctorBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(28));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(viewPix(75)));
        make.height.equalTo(@(viewPix(22)));
    }];
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.nameLabel);
    }];
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.numberLabel.mas_bottom).offset(viewPix(15));
        make.left.equalTo(self.nameLabel);
    }];
    [self.phoneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-viewPix(16));
        make.centerY.equalTo(self.phoneLabel);
        make.width.equalTo(@(viewPix(86)));
        make.height.equalTo(@(viewPix(28)));
    }];
}
-(CAGradientLayer *)shadowLayer{
    if(!_shadowLayer){
        _shadowLayer = [CAGradientLayer layer];
        _shadowLayer.frame = CGRectMake(0,0,Screen_W,topBarHeight+viewPix(115));
        _shadowLayer.startPoint = CGPointMake(0.5, 0);
        _shadowLayer.endPoint = CGPointMake(0.5, 1);
        _shadowLayer.colors = @[(__bridge id)[UIColor colorWithString:@"#E5F3FF"].CGColor, (__bridge id)[UIColor colorWithString:@"#F3F9FE"].CGColor, (__bridge id)[UIColor colorWithString:@"#FEFEFF"].CGColor];
        _shadowLayer.locations = @[@(0), @(0.5f), @(1.0f)];
    }
    return _shadowLayer;
}
-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UIImageView *)vipView{
    if(!_vipView){
        _vipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"patientVip"]];
    }
    return _vipView;
}

-(UIButton *)doctorBtn{
    if(!_doctorBtn){
        _doctorBtn = [UIButton buttonWithTitle:@"" titleFont:LGFontWeight(12, UIFontWeightMedium) textColor:@"#56BEA0" imageName:@"药球患者-医生"];
        _doctorBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _doctorBtn.imageEdgeInsets = UIEdgeInsetsMake(0, viewPix(10), 0, 0);
        _doctorBtn.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(12), 0, 0);
        _doctorBtn.backgroundColor = [UIColor colorWithString:@"#EBF8F3"];
        _doctorBtn.userInteractionEnabled = NO;
        _doctorBtn.cornerRidus = viewPix(11);
    }
    return _doctorBtn;
}

-(UILabel *)numberLabel{
    if(!_numberLabel){
        _numberLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _numberLabel;
}

-(UILabel *)phoneLabel{
    if(!_phoneLabel){
        _phoneLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _phoneLabel;
}

-(UIButton *)phoneButton{
    if(!_phoneButton){
        _phoneButton = [UIButton buttonWithTitle:@" 电话随访" titleFont:LGFontWeight(12, UIFontWeightMedium) textColor:@"#FFFFFF" imageName:@"药球患者-电话"];
        _phoneButton.backgroundColor = [UIColor colorWithString:@"#3291FF"];
        _phoneButton.cornerRidus = viewPix(14);
    }
    return _phoneButton;
}



@end
